/*
 * Created by SharpDevelop.
 * User: Rogerio
 * Date: 28/10/2008
 * Time: 8:41
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;

namespace csharp.common
{
	/// <summary>
	/// Description of InputBox.
	/// </summary>
	public class InputBox : KryptonForm
	{
		private System.Windows.Forms.TextBox txtValue;
		private System.ComponentModel.Container components = null;
	
		private InputBox(bool isPassword)
		{
			InitializeComponent(isPassword);
			
			//this.MaximumSize = this.Size;
			//this.MinimumSize = this.Size;
		}
	
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
	
		private void InitializeComponent(bool isPassword)
		{
			this.txtValue = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			//
			// txtValue
			//
			this.txtValue.Location = new System.Drawing.Point(16, 16);
			this.txtValue.Name = "txtValue";
			this.txtValue.Size = new System.Drawing.Size(256, 20);
			this.txtValue.TabIndex = 0;
			if (isPassword)
				this.txtValue.PasswordChar='*';
			this.txtValue.Text = "txtValue";
			this.txtValue.KeyDown += new
				System.Windows.Forms.KeyEventHandler(this.txtValue_KeyDown);
			//
			// InputBox
			//
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 53);
			this.ControlBox = false;
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.txtValue});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "InputBox";
			this.Text = "Password";
			this.StartPosition = FormStartPosition.CenterParent;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.ResumeLayout(false);			
	
		}
	
		private void txtValue_KeyDown(object sender,
			System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Enter)
				this.Close();
			if(e.KeyCode == Keys.Escape)
			{
	           	txtValue.Text="";
				this.Close();
			}				
		}
	
		public static string ShowInputBox(string text, bool isPassword)
		{
			InputBox box = new InputBox(isPassword);
			box.txtValue.Text = text;
			box.ShowDialog();
			return box.txtValue.Text;
		}    
	}	
}
